/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication2;
import java.io.*;
/**
 *
 * @author User
 */

public class Main {
public static final int MAXN=10;
    /**
     * @param args the command line arguments
     */
public static int push(int i,int stack[]) throws IOException
{
	if(i>=MAXN) return -2;
	BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        String s;
        s=in.readLine();
        stack[i]=Integer.parseInt(s);
	return i+1;
}
public static int pop(int i,int stack[])
{
	if(i<1) { System.out.println("Stack is empty"); return -1;}
        System.out.println(stack[i-1]);
	return i-1;
}
    public static void main(String[] args) throws IOException {
        int[] stack=new int[MAXN];
	int q,i=0;
        char c,o;
        boolean t=true;
	do
	{
	while(true)
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                c=(char)in.read();
		if(c=='>') i=push(i,stack); else
		if(c=='<') i=pop(i,stack); else
		if(c=='#') break;
		if (i==-2) {System.out.println("Stack overflow"); break;}
		if (i==-1) i=0;
	}
	System.out.println("Refine? 'YES'=1 'NO'=0");
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	q=in.read();
        o='0';
        i=q-(int)o;
	if(i==1) i=0; else t=false;
	} while(t);
        // TODO code application logic here
    }

}
